home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / program / 316 / libsrc / ctime.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-20  |  971 b   |  36 lines

  1.  
  2. /* not sure whether this is right... */
  3.  
  4. char ctime_buf[26];        /* is it safe to use a static one? */
  5.  
  6. char * month_name[] = {"???", "Jan", "Feb", "Mar", "Apr", "May", "Jun", 
  7.                "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
  8. char * day_name[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
  9.  
  10. char * ctime(date_and_time)
  11. long * date_and_time;
  12. {
  13.   int date = (*date_and_time >> 16) & 0xFFFF;
  14.   int time = *date_and_time & 0xFFFF;
  15.   int year, month, day, hour, min, sec;
  16.  
  17.   year = ((date >> 9) & 0x7F);
  18.   if ((year < 1) || (year > 19))    /* 1999 ought to be enough... */
  19.     year = 0;
  20.     else
  21.     year += 1980;
  22.   month = (date >> 5) & 0x0F;
  23.   if ((month < 1) || (month > 12))
  24.     month = 0;
  25.   day = date & 0x1F;
  26.   hour = (time >> 11) & 0x1F;
  27.   min = (time >> 5) & 0x3F;
  28.   sec = (time & 0x01F) * 2;
  29.   
  30.   sprintf(ctime_buf, "    %s %02d %02d:%02d:%02d %04d\n",
  31.     month_name[month], day, hour, min, sec, year);
  32.  
  33.   return((char * )&ctime_buf);
  34. }
  35.  
  36.